package org.shindou09.easytagforpage;

public class Page {

	private Integer currentPage;// 当前页�
	private Integer totalPages;// 总页数�
	private Integer totalRows;// 总行数�
	private Integer pageSize;// 页面的大小
	private boolean hasPreviousPage;// 是否有上一页
	private boolean hasNextPage;// 是否有下一页

	public Page(Integer currentPage, Integer totalPages, Integer pageSize,
			Integer totalRows) {
		this.currentPage = currentPage;
		this.totalPages = totalPages;
		this.totalRows = totalRows;
		this.pageSize = pageSize;
		refresh();
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
		refresh();
	}

	public boolean isHasNextPage() {
		return hasNextPage;
	}

	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}

	public boolean isHasPreviousPage() {
		return hasPreviousPage;
	}

	public void setHasPreviousPage(boolean hasPreviousPage) {
		this.hasPreviousPage = hasPreviousPage;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(Integer totalPages) {
		this.totalPages = totalPages;
		refresh();
	}

	public Integer getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(Integer totalRows) {
		this.totalRows = totalRows;
	}

	public void first() {
		this.currentPage = 1;
		refresh();
	}

	public void nextPage() {
		if (this.currentPage < this.totalPages)
			this.currentPage++;
		else
			this.currentPage = this.totalPages;
		refresh();
	}

	public void previousPage() {
		if (this.currentPage > 1)
			this.currentPage--;
		else
			this.currentPage = 1;
		refresh();
	}

	public void last() {
		this.currentPage = this.totalPages;
		refresh();
	}

	protected void refresh() {
		if (totalPages <= 1) {
			hasNextPage = false;
			hasPreviousPage = false;
		} else if (currentPage == 1) {
			hasNextPage = true;
			hasPreviousPage = false;
		} else if (currentPage == totalPages) {
			hasNextPage = false;
			hasPreviousPage = true;
		} else {
			hasNextPage = true;
			hasPreviousPage = true;
		}
	}
}
